package com.wanmait.recycle.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wanmait.recycle.mapper.ConfigMapper;
import com.wanmait.recycle.pojo.Config;
import com.wanmait.recycle.pojo.Userinfo;
import com.wanmait.recycle.service.ConfigService;
import com.wanmait.recycle.util.Pager;

@Service
@Transactional
public class ConfigServiceImpl implements ConfigService {

	@Resource
	private ConfigMapper configMapper;
	
	
	@Override
	public void insert(Config object) {
		// TODO Auto-generated method stub

	}

	//系统更改 ad 0227
	@Override
	public void update(Integer[] id,String[] value) {
		// TODO Auto-generated method stub
		for (int i = 0; i < id.length; i++) {
			configMapper.update(id[i],value[i]);
			
		}
		
	}

	@Override
	public void delete(Integer id) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(String ids) {
		// TODO Auto-generated method stub

	}

	@Override
	public Config findById(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	//系统列表 ad 0227
	@Override
	public List<Config> findAll() {
		// TODO Auto-generated method stub
		return configMapper.findAll();
	}

	@Override
	public int getDataCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<Config> findAll(Pager pager) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	
	public List<Config> findAll(Config object) {
		
		return configMapper.findAllByExample(object);
	}

	@Override
	public int getDataCount(Config object) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<Config> findAll(Pager pager, Config object) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void update(Config object) {
		// TODO Auto-generated method stub
		
	}
	//系统列表添加 ad 0319
	@Override
	public void insertMenu(Config config) {
		// TODO Auto-generated method stub
		configMapper.insertMenu(config);
	}
	//判断配置名是否重复
	@Override
	public boolean isConfigByExample(Config config) {
		System.out.println(config.getKey()+"**"+config.getTitle()+"**"+config.getValue());
		boolean f = false;
		if(configMapper.isConfigByExample(config)==null) {
			f = false;
		}else {
			f = true;
		}
		
		return  f;
	}

	@Override
	@Cacheable(value="recycle",key="'config'")
	public Map<String,Map<String, String>> findAllConfig() {
		Map<String,Map<String, String> > config = new HashMap<>();
		List<Config> c=  configMapper.findAll();
		for (Config config2 : c) {
			Map<String, String> cc = new HashMap<>();
			cc.put(config2.getKey(), config2.getValue());
			config.put(config2.getTitle(), cc);
		}
		return config;
	}
	
	@CacheEvict(value="recycle",allEntries=true)
	@Override
	public void clearCache() {
		
	}
}
